package controlador;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.event.WindowAdapter;
import vista.InterfazGraficaPrincipal;

public class ControladorPrincipal extends WindowAdapter implements ActionListener
{
	private InterfazGraficaPrincipal interfazPrincipal;
	
	public ControladorPrincipal()
	{
		interfazPrincipal= new InterfazGraficaPrincipal();
		interfazPrincipal.addListener((ActionListener)this);
		interfazPrincipal.addListener((WindowListener)this);
		interfazPrincipal.visualizarVentana();
	}

	public void actionPerformed(ActionEvent e) 
	{
		if (e.getActionCommand().equalsIgnoreCase("Clientes"))
		{
			new ControladorCliente(this);
			interfazPrincipal.ocultarVentana();
		}
		else if (e.getActionCommand().equalsIgnoreCase("Proveedores"))
		{		
			new ControladorProveedor(this);
			interfazPrincipal.ocultarVentana();
		}
		else if (e.getActionCommand().equalsIgnoreCase("Ingredientes"))
		{		
			new ControladorIngrediente(this);
			interfazPrincipal.ocultarVentana();
		}
		else if (e.getActionCommand().equalsIgnoreCase("Categorias"))
		{		
			new ControladorCategoria(this);
			interfazPrincipal.ocultarVentana();
		}
		else if (e.getActionCommand().equalsIgnoreCase("Productos"))
		{		
			new ControladorProducto(this);
			interfazPrincipal.ocultarVentana();
		}
	    else if (e.getActionCommand().equalsIgnoreCase("Salir"))
		{
	    	interfazPrincipal.descargarMemoria();
			System.exit(0);
		}
	    else if (e.getActionCommand().equalsIgnoreCase("Factura Compra"))
		{		
			new ControladorCompra(this);
			interfazPrincipal.ocultarVentana();
		}
	    else if (e.getActionCommand().equalsIgnoreCase("Factura Venta"))
		{		
			new ControladorVenta(this);
			interfazPrincipal.ocultarVentana();
		}
	    else if (e.getActionCommand().equalsIgnoreCase("Reporte Ingredientes"))
		{		
			new ControladorReporteIngrediente(this);
			interfazPrincipal.ocultarVentana();
		}
	    else if (e.getActionCommand().equalsIgnoreCase("Reporte Ventas"))
		{		
			new ControladorReporteVenta(this);
			interfazPrincipal.ocultarVentana();
		}
		
	}

	public void visualizarVentanaPrincipal()
	{
		interfazPrincipal.visualizarVentana();
	}

	@Override
	public void windowClosing(WindowEvent arg0) {
		interfazPrincipal.descargarMemoria();
		System.exit(0);
	}

	

	

}
